package com.xjy.web.controller.system.basics;

import java.util.List;
import java.util.Arrays;
import java.util.stream.Collectors;

import com.xjy.system.domain.SysPayaccount;
import com.xjy.system.domain.bo.SysFundaccountQueryBo;
import com.xjy.system.domain.vo.SysFundaccountVo;
import com.xjy.system.service.ISysFundaccountService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.xjy.common.annotation.RepeatSubmit;
import com.xjy.common.annotation.Log;
import com.xjy.common.core.controller.BaseController;
import com.xjy.common.core.domain.AjaxResult;
import com.xjy.common.enums.BusinessType;
import com.xjy.system.domain.vo.SysPayaccountVo;
import com.xjy.system.domain.bo.SysPayaccountQueryBo;
import com.xjy.system.domain.bo.SysPayaccountAddBo;
import com.xjy.system.domain.bo.SysPayaccountEditBo;
import com.xjy.system.service.ISysPayaccountService;
import com.xjy.common.utils.poi.ExcelUtil;
import com.xjy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 支付账户信息Controller
 *
 * @author zc
 * @date 2022-02-09
 */
@Api(value = "支付账户信息控制器", tags = {"支付账户信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/SysPayaccount")
public class SysPayaccountController extends BaseController {

    private final ISysPayaccountService iSysPayaccountService;

	private final ISysFundaccountService iSysFundaccountService;
    /**
     * 查询支付账户信息列表
     */
    @ApiOperation("查询支付账户信息列表")
    @PreAuthorize("@ss.hasPermi('system:SysPayaccount:list')")
    @GetMapping("/list")
    public TableDataInfo<SysPayaccountVo> list(@Validated SysPayaccountQueryBo bo) {
        return iSysPayaccountService.queryPageList(bo);
    }

	/**
	 * 查询支付账户信息列表
	 */
	@ApiOperation("查询支付账户信息列表")
	@PreAuthorize("@ss.hasPermi('system:SysPayaccount:list')")
	@GetMapping("/selectList")
	public List<SysPayaccountVo> selectList(@Validated SysPayaccountQueryBo bo) {
		bo.setAuditStatus(true);
		SysFundaccountQueryBo sysFundaccountQueryBo = new SysFundaccountQueryBo();
		sysFundaccountQueryBo.setAuditStatus(true);

		List<SysFundaccountVo>  sysFundaccountVoList = iSysFundaccountService.queryList(sysFundaccountQueryBo);
		List<Long> idList = sysFundaccountVoList.stream().map(SysFundaccountVo::getAccountId).collect(Collectors.toList());
		bo.setIdList(idList);
		return iSysPayaccountService.queryList(bo);
	}


	/**
	 * 根据项目id查询账户信息
	 */
	@ApiOperation("查询支付账户信息列表")
	@GetMapping("/listpay")
	public List<SysPayaccount> list(Long prjId) {
		return iSysPayaccountService.queryPageListPay(prjId);
	}

    /**
     * 导出支付账户信息列表
     */
    @ApiOperation("导出支付账户信息列表")
    @PreAuthorize("@ss.hasPermi('system:SysPayaccount:export')")
    @Log(title = "支付账户信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<SysPayaccountVo> export(@Validated SysPayaccountQueryBo bo) {
        List<SysPayaccountVo> list = iSysPayaccountService.queryList(bo);
        ExcelUtil<SysPayaccountVo> util = new ExcelUtil<SysPayaccountVo>(SysPayaccountVo.class);
        return util.exportExcel(list, "支付账户信息");
    }

    /**
     * 获取支付账户信息详细信息
     */
    @ApiOperation("获取支付账户信息详细信息")
    @PreAuthorize("@ss.hasPermi('system:SysPayaccount:query')")
    @GetMapping("/{id}")
    public AjaxResult<SysPayaccountVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iSysPayaccountService.queryById(id));
    }

    /**
     * 新增支付账户信息
     */
    @ApiOperation("新增支付账户信息")
    @PreAuthorize("@ss.hasPermi('system:SysPayaccount:add')")
    @Log(title = "支付账户信息", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody SysPayaccountAddBo bo) {
        return toAjax(iSysPayaccountService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改支付账户信息
     */
    @ApiOperation("修改支付账户信息")
    @PreAuthorize("@ss.hasPermi('system:SysPayaccount:edit')")
    @Log(title = "支付账户信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping("/edit")
    public AjaxResult<Void> edit(@Validated @RequestBody SysPayaccountEditBo bo) {
        return toAjax(iSysPayaccountService.updateByEditBo(bo) ? 1 : 0);
    }

	/**
	 * 修改支付账户信息
	 */
	@ApiOperation("修改支付账户信息")
	@PreAuthorize("@ss.hasPermi('system:SysPayaccount:edit')")
	@Log(title = "支付账户信息", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PutMapping("/audit")
	public AjaxResult<Void> audit(@Validated @RequestBody SysPayaccountEditBo bo) {
		return toAjax(iSysPayaccountService.auditByEditBo(bo) ? 1 : 0);
	}

    /**
     * 删除支付账户信息
     */
    @ApiOperation("删除支付账户信息")
    @PreAuthorize("@ss.hasPermi('system:SysPayaccount:remove')")
    @Log(title = "支付账户信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iSysPayaccountService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }


}
